$(function(){
	//登录验证的url
	var loginUrl = "/o2oSystem/local/logincheck";
	//从地址栏获取usertype
	var usertype = getQueryString("usertype");
	//登录次数，累计登录次数三次失败后，自动弹出验证码
	var loginCount=0;

	//提交后台
	$("#submit").click(function(){
		//账号
		var username = $("#username").val();
		//密码
		var password = $("#psw").val();
		//验证码
		var verifyCodeActual = $("#j_captcha").val();
		var needVerify = false;
		if(loginCount >= 3){
			if(!verifyCodeActual){
				$.toast("请输入验证码");
				return;
			}else{
				needVerify = true;
			}
		}
		$.ajax({
			url:loginUrl,
			async:false,
			cache:false,
			type:"post",
			dataType:"json",
			data:{username:username,
				password:password,
				verifyCodeActual:verifyCodeActual,
				needVerify:needVerify//是否需要验证码
			},
			success:function(data){
				console.log(data);
				if(data.success){
					$.toast("登录成功");
					if(usertype == 1){
						window.location.href="/o2oSystem/frontend/index";
					}
					else{
						window.location.href="/o2oSystem/shopadmin/shoplist";
					}
				}else{
					$.toast("登录失败");
					console.log(data.errMsg);
					loginCount ++;
					if(loginCount >=3){
						$("#verifyPart").show();
					}
				}
			}
		});
	});
})